<template>
  <div>
    <h1>已经登录</h1>
    <button type="info" @click="getData">获取数据</button>
<br/>
    <div><h2>{{ str }}</h2></div><br/>
    <button type="warning" @click="logout">退出登录</button>
  </div>
</template>

<script>
  import cookies from '../../assets/js/common/cookies';

  export default {
    middleware: 'auth',
    data() {
      return {
        str: ''
      }
    },
    methods: {
      async getData() {
        let api = await this.$axios.get('/api/user');
        console.log(api);
        this.str = api.data;
      },
      logout() {
        cookies.removeToken();
        this.$store.commit('SET_TOKEN', null);
        this.$router.push("/");
      }
    }
  }
</script>

<style>

</style>
